Skip to content

Button: remove ui-state-active on button disable. Fixed #9602 - ui-state-active remains after disable #1151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from

Conversation

robotdan
Copy link
Contributor

Button: remove ui-state-active on button disable. Fixed #9602 - ui-state-active class remains after disabling a button

…ate-active class remains after disabling a button
@robotdan
Copy link
Contributor Author

Added testcase from bug report to use this branch bug_9602.
http://jsfiddle.net/VeX37/1/

@tjvantoll
Copy link
Member

There's one problem with this approach that I didn't think about earlier. We can't remove ui-state-active when checkboxes and radio buttons are disabled - http://jsfiddle.net/tj_vantoll/6R2Ff/.

@robotdan
Copy link
Contributor Author

I'll fix that and add some additional test cases to cover those scenarios.

@robotdan
Copy link
Contributor Author

Checked in some additional code to only remove the ui-state-active class from a <button> or <input type="button"> and added additional test cases to cover those scenarios.

These two test cases should now show the same behavior for a checkbox

And the test case for issue 9602
http://jsfiddle.net/VeX37/1/

@@ -250,7 +250,11 @@ $.widget( "ui.button", {
this.widget().toggleClass( "ui-state-disabled", !!value );
this.element.prop( "disabled", !!value );
if ( value ) {
this.buttonElement.removeClass( "ui-state-focus" );
if ( this.buttonElement.is( "input:button, button" ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also support turning <a> elements and even generic elements like <div>s into buttons. It might be better to flip the logic so you explicitly check for radio buttons and checkboxes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point, I did prototype that logic initially but I had a few problems with it. But that is probably a better strategy, I'll take another look at it.

…ate-active remains after disable

Refactor unit tests after flipping logic to specifically look for radio
and checkbox, also added div, and a elements for unit test.
@robotdan
Copy link
Contributor Author

I updated the logic as suggested to specifically check for radio and checkbox elements. I also refactored the unit tests a bit to add <div> and <a> elements to the test and make sure I'm validating the class on the correct element when looking at the button widget from a checkbox or radio element.

I updated these two jsfiddle test cases to include more button options.

@tjvantoll
Copy link
Member

👍

$.each( elements, function() {

var element = $( this ).first(),
buttonElement = element.is( ":checkbox, :radio" ) ? element.next() : element,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:checkbox and :radio are discouraged; use [type=...] selectors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store the result of this check in a variable since you need to know this later too.

@scottgonzalez
Copy link
Member

Please move the test to button_options.js, immediately below the existing disabled tests, and prefix the test name with "disabled, ".

…ate-active class remains after disabling a button

Few small formatting changes based upon comments. Moved unit test to
button_options.js from button_methods.js.
@robotdan
Copy link
Contributor Author

Resolved comments from @scottgonzalez and moved unit test to button_options.js. Thanks.

];

$.each( elements, function() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blank line here.

@scottgonzalez
Copy link
Member

A few minor issues, but other than that this looks good to go. Thanks.

…ate-active class remains after disabling a button

use .button( “widget” ) instead of checking for radio or checkbox.
@jzaefferer
Copy link
Member

@scottgonzalez there were updates, but no comment, after your last comment - can you review this again?

$( "<div></div>" ),
$( "<input type='checkbox' id='checkbox' checked><label for='checkbox'></label>" ),
$( "<input type='radio' id='radio' checked><label for='radio'></label>" )
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is indented too much.

@scottgonzalez
Copy link
Member

Thanks, I squashed everything and landed this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants